<template>
  <div>
    <zm-dialog
      title="新增导出模板"
      :visible.sync="value"
      append-to-body
      :before-close="dialogClose"
      :close-on-click-modal="false"
      :keep-alive="true"
    >
    <zm-form ref="form" :model="form" :rules="rules">
     <zm-form-item label="导出模板名称" prop="name">
       <el-input class="w300" v-model.trim="form.name" maxlength="20" clearable show-word-limit placeholder="请填写"></el-input>
     </zm-form-item>
     <zm-form-item label="是否公开模板" prop="isPublic">
       <el-switch v-model="form.isPublic" active-color="#13ce66" active-value="1" inactive-value="0"></el-switch>
     </zm-form-item>
    </zm-form>

      <div slot="footer" class="tr">
        <el-button @click="dialogClose" type="info">取消</el-button>
        <el-button @click="onSave" type="primary">保存</el-button>
      </div>
    </zm-dialog>
  </div>
</template>
<script>
import dialogMixin from '@/mixins/dialogMixin'
import {createUpdate} from '@/api/src/exportTemplate'
export default {
  name: 'CreateTemplate',
  components: {},
  mixins: [dialogMixin],
  props: {
    type: {
      type: String,
      default: ''
    },
    exportId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      form: {
        name: '',
        isPublic: '1'
      },
      rules: {
        name: {
          required: true,
          message: '请填写模板名称'
        },
        isPublic: {
          required: true,
          message: '请选择'
        }
      }
    }
  },
  computed: {},
  watch: {},
  created () {},
  methods: {
    onSave () {
      this.$refs.form.validate(async valid => {
        if (valid) {
          const params = {
            name: this.form.name,
            type: this.type,
            exportField: this.exportId,
            isPublic: this.form.isPublic
          }
          await createUpdate(params)
          this.$emit('after-save')
          this.dialogClose()
        }
      })
    }
  }
}
</script>
<style scoped lang='scss'>
</style>
